import time,asyncio,functools

def loop_stop(loop,future):
    loop.stop()

async def work(t):
    print('start')
    await asyncio.sleep(t)
    print(f'after {t}s stop')

def main():
    loop=asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    tasks=asyncio.gather(work(1),work(2))
    tasks.add_done_callback(functools.partial(loop_stop,loop))
    loop.run_forever()
    loop.close()

start=time.time()
main()
end=time.time()
print('Running time:{:.4f}s'.format(end-start))
